#!/usr/bin/env python3
import os
from cairosvg import svg2png

def convert_svg_to_png(input_folder, output_folder, size=24):
    # 创建输出文件夹（如果不存在）
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)

    # 遍历输入文件夹中的所有文件
    for filename in os.listdir(input_folder):
        if filename.endswith('.svg'):
            svg_path = os.path.join(input_folder, filename)
            png_filename = os.path.splitext(filename)[0] + '.png'
            png_path = os.path.join(output_folder, png_filename)

            # 转换 SVG 到 PNG
            with open(svg_path, 'rb') as svg_file:
                svg_content = svg_file.read()
                svg2png(bytestring=svg_content, write_to=png_path, output_width=size, output_height=size)

            print(f'Converted {svg_path} to {png_path}')

if __name__ == '__main__':
    input_folder = './svg-icons/'  # 替换为你的 SVG 文件夹路径
    output_folder = './resource/'  # 替换为你的 PNG 文件夹路径
    convert_svg_to_png(input_folder, output_folder, 48)